<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__user">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <!-- <el-form-item>
          <el-input
            v-model="dataForm.username"
            :placeholder="$t('user.username')"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <ren-select
            v-model="dataForm.gender"
            dict-type="gender"
            :placeholder="$t('user.gender')"
          ></ren-select>
        </el-form-item>

        <el-form-item>
          <ren-dept-tree
            v-model="dataForm.deptId"
            :placeholder="$t('dept.title')"
            :query="true"
          ></ren-dept-tree>
         </el-form-item> -->
        <el-form-item>
          <el-select
            v-model="dataForm.industryName"
            placeholder="请选择行业名称"
          >
            <el-option
              v-for="item in industryNameList"
              :key="item"
              :value="item"
              :label="item"
            ></el-option>
          </el-select>
          <!-- 行业 -->
          <!-- <ren-select v-model="queryForm.gender" dict-type="gender" :placeholder="$t('user.gender')"></ren-select> -->
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t("query") }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button @click="result()">重置</el-button>
        </el-form-item>
      </el-form>
      <div class="table-top">
        <div class="left">
          <div class="top-line"></div>
          行业云图列表
        </div>
        <div class="right">
          <div class="table-top-btn" @click="addOrUpdateHandle()">新增</div>
          <div class="table-top-btn" @click="deleteHandle()">删除</div>
        </div>
      </div>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        stripe
        @selection-change="dataListSelectionChangeHandle"
        @sort-change="dataListSortChangeHandle"
        style="width: 100%"
      >
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50"
        ></el-table-column>
        <el-table-column
          prop="industryName"
          label="行业"
          sortable="custom"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="iconUrlNew"
          label="图标"
          header-align="center"
          align="center"
        >
          <template slot-scope="{ row }">
            <img
                v-if="row.iconUrl"
              :src="'/api' + row.iconUrl"
              style="width: 50px; height: 50px; background: gray"
            />
          </template>
        </el-table-column>
        <el-table-column
          prop="cloudMapName"
          label="云图名称"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="sort"
          label="排序"
          sortable="custom"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="url"
          label="链接"
          sortable="custom"
          header-align="center"
          width="300"
        >
        </el-table-column>
        <el-table-column
          prop="status"
          label="状态"
          sortable="custom"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <span>{{scope.row.status==1?'禁用':'正常'}}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="创建日期"
          sortable="custom"
          header-align="center"
          align="center"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="creatorName"
          label="创建者"
          sortable="custom"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="100"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="addOrUpdateHandle(scope.row.id)"
              >{{ $t("update") }}</el-button
            >
            <el-button
              type="text"
              size="small"
              @click="deleteHandle(scope.row.id)"
              >{{ $t("delete") }}</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="+limit"
        :total="+total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        :industry-name-list="industryNameList"
        @refreshDataList="getDataList"
      ></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './atlas-add-or-update'
const URL_GET_ALL_MODULE = '/cgjybzIndustry/getModuleInfo'

export default {
  mixins: [mixinViewModule],
  data () {
    return {
      industryNameList: [],
      mixinViewModuleOptions: {
        getDataListURL: '/cgjybzIndustryCloudMapInfo/page',
        getDataListIsPage: true,
        deleteURL: '/cgjybzIndustryCloudMapInfo',
        deleteIsBatch: true,
        exportURL: ''
      },
      dataForm: {
        menuType: '行业云图',
        industryName: ''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  created () {
    this.$http.get(URL_GET_ALL_MODULE).then(({ data: resp }) => {
      const { data } = resp
      this.industryNameList = data.reduce((ret, cur) => {
        if (cur.industryName) {
          if (!ret.includes(cur.industryName)) {
            ret.push(cur.industryName)
          }
        }
        return ret
      }, [])
    })
  },
  methods: {
    result () {
      this.dataForm.industryName = ''
      this.getDataList()
    }
  }
}
</script>
